﻿using LoA.Shared.Interfaces;

namespace Microsoft.Xna.Framework.Graphics {
	public static class DrawingExtensions {
		public static void DrawMap(this Model model, ICamera Camera) {
			Matrix worldMatrix = Matrix.Identity;
			if (model.Tag.GetType( ).GetInterface(typeof(IMapInfo).Name) != null) {
				Vector2 position = (model.Tag as IMapInfo).GetRealPosition( );
				worldMatrix = Matrix.CreateTranslation(position.X, 0, position.Y);
			}
			Matrix[ ] boneTransforms = new Matrix[model.Bones.Count];
			model.CopyAbsoluteBoneTransformsTo(boneTransforms);

			// Strasznie wyblaknięte i bez życia rysowanie
			//model.Draw(worldMatrix, Camera.ViewMatrix, Camera.ProjectionMatrix);

			foreach (ModelMesh mesh in model.Meshes) {
				foreach (BasicEffect effect in mesh.Effects) {
					effect.World = boneTransforms[mesh.ParentBone.Index] * worldMatrix;
					effect.View = Camera.ViewMatrix;
					effect.Projection = Camera.ProjectionMatrix;

					effect.PreferPerPixelLighting = true;
					//effect.VertexColorEnabled = true;

					Camera.SetLighting(effect);
				}
				mesh.Draw( );
			}
		}
	}
}
